package com.lsa.skienna.challenge.chap4.the110405_ShoomakerProblem;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class ShoomakerProblem implements Runnable{
	
	public static void main(String[] args) throws Exception {
		new ShoomakerProblem().run();
	}
	
	@Override
	public void run() {
		TaskReader taskReader = new TaskReader(System.in);
		ResultWriter resultWriter = new ResultWriter(System.out);
		try {
			Task task = taskReader.readNextTask();
			while(task != null){
				imposeBestOrdering(task);
				resultWriter.write(task.orders);
				task = taskReader.readNextTask();
				if (task != null) {
					resultWriter.writeTaskBreak();
				}
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	static void imposeBestOrdering(Task task) {
		Arrays.sort(task.orders, new Comparator<ShoomakerOrder>() {
			@Override
			public int compare(ShoomakerOrder o1, ShoomakerOrder o2) {
				return ShoomakerProblem.compare(o1, o2);
			}
		});
	}
	
	static int compare(ShoomakerOrder o1, ShoomakerOrder o2) {
		int c = (int)Math.signum(score(o2) - score(o1));
		if (c == 0) {
			c = o1.number - o2.number;
		}
		return c;
	}
	
	static int compareLexiNumber(ShoomakerOrder o1, ShoomakerOrder o2) {
		return o1.number - o2.number;
	}
	
	static double score(ShoomakerOrder o) {
		return (double)o.penalty / (double)o.completionTime;
	}
	
	static class ResultWriter{
		private static final String lineSeparator = System.getProperty("line.separator");
		
		private BufferedWriter writer;
		ResultWriter(OutputStream stream) {
			this.writer = new BufferedWriter(new OutputStreamWriter(stream));
		}
		
		void write(ShoomakerOrder[] orders) throws IOException{
			for (int i = 0; i < orders.length; i++) {
				if (i > 0) {
					writer.write(" ");
				}
				writer.write(orders[i].number+ "");
			}
			writer.write(lineSeparator);
			writer.flush();
		}
		
		void writeTaskBreak() throws IOException {
			writer.write(lineSeparator);
		}
	}
	
	static class TaskReader{
		private BufferedReader reader;
		private boolean isFirst;
		private int caseNumber;

		TaskReader(InputStream stream) {
			this.reader = new BufferedReader(new InputStreamReader(stream));
			this.isFirst = true;
		}
		
		Task  readNextTask() throws IOException{
			if (isFirst) {
				String line = reader.readLine();
				if (line == null){
					return null;
				}
				
				caseNumber = Integer.parseInt(line.trim());
				isFirst = false;
				reader.readLine();
			}
			
			if (caseNumber-- > 0) {
				String line = reader.readLine();
				if (line == null){
					return null;
				}
				
				int orderNumber = Integer.parseInt(line.trim());
				ShoomakerOrder[] orders = new ShoomakerOrder[orderNumber];
				for (int i = 0; i < orderNumber; i++) {
					line = reader.readLine();
					Scanner scanner = new Scanner(line);
					int completionTime = scanner.nextInt();
					int penalty = scanner.nextInt();
					ShoomakerOrder order = new ShoomakerOrder(i + 1, completionTime, penalty);
					orders[i] = order;
				}
				reader.readLine();
				
				return new Task(orders);
			}
			return null;
		}
	}
	
	static class Task {
		public ShoomakerOrder[] orders;

		public Task(ShoomakerOrder[] orders) {
			this.orders = orders;
		}

		@Override
		public String toString() {
			return "Task [orders=" + Arrays.toString(orders) + "]";
		}
	}
	
	static class ShoomakerOrder{
		public final int number;
		public final int completionTime;
		public final int penalty;
		
		public ShoomakerOrder(int number, int completionTime, int penalty) {
			this.completionTime = completionTime;
			this.penalty = penalty;
			this.number = number;
		}

		@Override
		public String toString() {
			return "[completionTime=" + completionTime
					+ ", penalty=" + penalty + "]";
		}

		@Override
		public ShoomakerOrder clone() throws CloneNotSupportedException {
			return new ShoomakerOrder(number, completionTime, penalty);
		}
	}
}
